package com.tssup.fesco.service.impl;

import com.tssup.fesco.common.enumeration.LogisticsStatus;
import com.tssup.fesco.common.enumeration.OrderAppStatus;
import com.tssup.fesco.common.enumeration.OrderStatus;
import com.tssup.fesco.common.enumeration.PayStatus;
import com.tssup.fesco.common.enums.YesNo;
import com.tssup.fesco.sales.order.persistent.pojo.IOrder;
import com.tssup.fesco.service.OrderStatusService;
import org.springframework.stereotype.Service;

/**
 *
 * @author franco.cheng
 * @date 2017/3/14
 */
@Service
public class OrderStatusServiceImpl implements OrderStatusService {

    @Override
    public OrderAppStatus getAppStatus(IOrder order) {
        Integer orderstatus = order.getOrderStatus() ;
        Integer logisticsstatus = order.getLogisticsStatus() ;
        Integer paystatus = order.getPayStatus() ;
        Integer cancelstatus = order.getDelStatus()==null?YesNo.NO.getValue():order.getDelStatus() ;
        Integer evaluateStatus = order.getEvaluateStatus() != null ? order.getEvaluateStatus() : YesNo.NO.getValue();

        if (YesNo.YES.getValue().equals(cancelstatus) || OrderStatus.CANCELED.getValue().equals(orderstatus) || LogisticsStatus.CANCLE.getValue().equals(logisticsstatus)){
            return OrderAppStatus.CANCEL  ;
        } else if( PayStatus.NOT_PAY.getValue().equals(paystatus) || PayStatus.IN_PAY.getValue().equals(paystatus) ){
            return OrderAppStatus.PREPAY ;
        } else if(LogisticsStatus.NOT_SHIPPED.getValue().equals(logisticsstatus)
                && PayStatus.PAID.getValue().equals(paystatus)
                && (OrderStatus.CONFIRMED.getValue().equals(orderstatus) || OrderStatus.OFC_SPLIT_ORDER.getValue().equals(orderstatus))){
            return OrderAppStatus.PRESEND  ;
        } else if(LogisticsStatus.SHIPPED.getValue().equals(logisticsstatus)
                || LogisticsStatus.SHIPPED_PART.getValue().equals(logisticsstatus)
                || LogisticsStatus.SHIPPED_ALL.getValue().equals(logisticsstatus)
                || LogisticsStatus.SHIPPING.getValue().equals(logisticsstatus)){
            return OrderAppStatus.SENDING ;
        } else if (LogisticsStatus.RECEIVED.getValue().equals(logisticsstatus) && (YesNo.NO.getValue().equals(evaluateStatus) || evaluateStatus == null)){
            return OrderAppStatus.EVALUATE;
        } else  if (LogisticsStatus.RECEIVED.getValue().equals(logisticsstatus) && YesNo.YES.getValue().equals(evaluateStatus)) {
            return OrderAppStatus.COMPLETED;
        }
        return OrderAppStatus.ALL;
    }
}
